package vnreal.evaluations.metrics;

import java.util.Iterator;

import vnreal.demands.BandwidthDemand;
import vnreal.mapping.Mapping;
import vnreal.network.substrate.SubstrateLink;
import vnreal.resources.AbstractResource;
import vnreal.resources.BandwidthResource;

public class BandwidthCost extends AbstractEvaluation {

	@Override
	public double calculate() {
		double linkCost = 0;
		BandwidthDemand tmpBwDem;
		for (Iterator<SubstrateLink> tmpSLink = stack.getSubstrate().getEdges().iterator(); tmpSLink.hasNext();) {
			SubstrateLink currSLink = tmpSLink.next();
			for (AbstractResource res : currSLink) {
				if (res instanceof BandwidthResource) {
					for (Mapping f : res.getMappings()) {
						tmpBwDem = (BandwidthDemand) f.getDemand();
						linkCost += tmpBwDem.getDemandedBandwidth();
					}
				}
			}
		}
		return linkCost;
	}

	@Override
	public String toString() {
		return "BandwidthCost";
	}

}
